package game;

import org.newdawn.slick.Color;
import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

import components.Item;
import components.Space;

public class Result extends BasicGameState{
	
	public int[] wins;
	private int step;
	private int winner;
	private int maxWins;
	private Image[] win,loose;
	private Font font;
	private int mod;
	private components.Map map;

	public Result(int state, int winner, Image[] win, Image[] loose, int maxWins, int mod, components.Map map){
		this.winner=winner;
		this.win=win;
		this.loose=loose;
		this.maxWins=maxWins;
		this.mod=mod;
		this.map=map;
		this.font =new TrueTypeFont (new java.awt.Font("Baskerville Old Face",0,64),false );
	}

	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
		this.wins = new int[this.map.bomber.length];
		
		for(int i = 0; i<this.wins.length; i++){
			this.wins[i]=this.map.bomber[i].wins;
		}
		this.step=(game.Main.sizey-100)/this.wins.length;
		
	}

	@Override
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
		if(this.mod==4){
			g.setColor(Color.pink);
			g.fillRect(0, 0, Main.sizex, Main.sizex);
			g.setColor(Color.white);
		}
		g.setFont(font);
		int help = winner+1;
		for(int i=0;i<this.wins.length;i++){
			if(i==winner){
				win[i].draw(100, 50+i*this.step, 45, 45);
				if(this.wins[winner]>=maxWins){
					g.drawString("Player "+ help +" wins!!!!", 145, 50+i*this.step);
				}
			}
			else{
				loose[i].draw(100, 50+i*this.step, 45, 45);
			}
			for(int j =0; j<this.wins[i]; j++){
				game.Multiplayer.cup.draw(150+j*55, 50+i*this.step ,45,45);
			}
		}
	}

	@Override
	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {

		Input in = gc.getInput();

	}

	@Override
	public int getID() {
		return 7;
	}


}
